// 购物网站Mock数据模块

import type { 
  Product, 
  Category, 
  Banner, 
  Order, 
  User, 
  Address,
  Review,
  Coupon 
} from '@/types/mall'
import { generateId } from '@/utils/mall'

// 商品分类Mock数据
export const mockCategories: Category[] = [
  { id: '1', name: '手机数码', icon: 'phone', level: 1, sort: 1 },
  { id: '11', name: '手机', icon: 'phone', level: 2, sort: 1, parentId: '1' },
  { id: '12', name: '平板电脑', icon: 'tablet', level: 2, sort: 2, parentId: '1' },
  { id: '13', name: '智能手表', icon: 'watch', level: 2, sort: 3, parentId: '1' },
  { id: '14', name: '耳机音响', icon: 'headphone', level: 2, sort: 4, parentId: '1' },
  
  { id: '2', name: '电脑办公', icon: 'laptop', level: 1, sort: 2 },
  { id: '21', name: '笔记本', icon: 'laptop', level: 2, sort: 1, parentId: '2' },
  { id: '22', name: '台式机', icon: 'desktop', level: 2, sort: 2, parentId: '2' },
  { id: '23', name: '显示器', icon: 'monitor', level: 2, sort: 3, parentId: '2' },
  
  { id: '3', name: '家用电器', icon: 'tv', level: 1, sort: 3 },
  { id: '4', name: '服饰内衣', icon: 'shirt', level: 1, sort: 4 },
  { id: '5', name: '鞋靴箱包', icon: 'shoe', level: 1, sort: 5 },
  { id: '6', name: '运动户外', icon: 'basketball', level: 1, sort: 6 },
  { id: '7', name: '美妆护肤', icon: 'star', level: 1, sort: 7 },
  { id: '8', name: '母婴用品', icon: 'baby', level: 1, sort: 8 },
]

// 轮播图Mock数据
export const mockBanners: Banner[] = [
  {
    id: '1',
    title: '新品首发',
    image: 'https://store.storeimages.cdn-apple.com/8756/as-images.apple.com/is/iphone-15-pro-max-naturaltitanium-pdp-image-position-1a_CN.jpg',
    link: '/pages/goodsDetail/index?id=1',
    linkType: 'product',
    sort: 1,
    status: 'active',
  },
  {
    id: '2',
    title: '限时优惠',
    image: 'https://store.storeimages.cdn-apple.com/8756/as-images.apple.com/is/macbook-air-13-m3-midnight-pdp-image-position-1_CN.jpg',
    link: '/pages/goodsDetail/index?id=2',
    linkType: 'product',
    sort: 2,
    status: 'active',
  },
  {
    id: '3',
    title: '热销爆款',
    image: 'https://store.storeimages.cdn-apple.com/8756/as-images.apple.com/is/airpods-pro-2nd-gen-hero-select-202209_FMT_WHH.jpg',
    link: '/pages/goodsDetail/index?id=3',
    linkType: 'product',
    sort: 3,
    status: 'active',
  },
]

// 商品Mock数据
export const mockProducts: Product[] = [
  {
    id: '1',
    name: 'iPhone 15 Pro Max',
    description: '全新iPhone 15 Pro Max，搭载A17 Pro芯片，钛金属设计，专业级摄像系统',
    categoryId: '11',
    brandId: 'apple',
    images: [
      'https://store.storeimages.cdn-apple.com/8756/as-images.apple.com/is/iphone-15-pro-max-naturaltitanium-pdp-image-position-1a_CN.jpg',
      'https://store.storeimages.cdn-apple.com/8756/as-images.apple.com/is/iphone-15-pro-max-naturaltitanium-pdp-image-position-2_CN.jpg',
    ],
    defaultPrice: 999900,
    originalPrice: 1099900,
    sales: 1200,
    stock: 50,
    status: 'active',
    rating: 4.8,
    reviewCount: 520,
    tags: ['新品', '热销'],
    createdAt: new Date().toISOString(),
    updatedAt: new Date().toISOString(),
  },
  {
    id: '2',
    name: 'MacBook Air M3',
    description: '搭载M3芯片的MacBook Air，轻薄便携，性能卓越',
    categoryId: '21',
    brandId: 'apple',
    images: [
      'https://store.storeimages.cdn-apple.com/8756/as-images.apple.com/is/macbook-air-13-m3-midnight-pdp-image-position-1_CN.jpg',
    ],
    defaultPrice: 899900,
    originalPrice: 999900,
    sales: 800,
    stock: 30,
    status: 'active',
    rating: 4.9,
    reviewCount: 350,
    tags: ['推荐'],
    createdAt: new Date().toISOString(),
    updatedAt: new Date().toISOString(),
  },
  {
    id: '3',
    name: 'AirPods Pro 3',
    description: '全新AirPods Pro，主动降噪更出色，音质更佳',
    categoryId: '14',
    brandId: 'apple',
    images: [
      'https://store.storeimages.cdn-apple.com/8756/as-images.apple.com/is/airpods-pro-2nd-gen-hero-select-202209_FMT_WHH.jpg',
    ],
    defaultPrice: 189900,
    originalPrice: 219900,
    sales: 2000,
    stock: 100,
    status: 'active',
    rating: 4.7,
    reviewCount: 850,
    tags: ['热销', '推荐'],
    createdAt: new Date().toISOString(),
    updatedAt: new Date().toISOString(),
  },
  {
    id: '4',
    name: 'Apple Watch Ultra 2',
    description: '专为极限运动打造的Apple Watch，钛金属表壳，超长续航',
    categoryId: '13',
    brandId: 'apple',
    images: [
      'https://store.storeimages.cdn-apple.com/8756/as-images.apple.com/is/watch-ultra-2-hero-select-202309_GEO_CN.jpg',
    ],
    defaultPrice: 629900,
    originalPrice: 699900,
    sales: 600,
    stock: 25,
    status: 'active',
    rating: 4.8,
    reviewCount: 280,
    tags: ['新品'],
    createdAt: new Date().toISOString(),
    updatedAt: new Date().toISOString(),
  },
  {
    id: '5',
    name: 'iPad Air 5',
    description: '搭载M1芯片的iPad Air，轻薄便携，性能强劲',
    categoryId: '12',
    brandId: 'apple',
    images: [
      'https://store.storeimages.cdn-apple.com/8756/as-images.apple.com/is/ipad-air-hero-select-wifi-purple-202203.jpg',
    ],
    defaultPrice: 439900,
    originalPrice: 489900,
    sales: 950,
    stock: 40,
    status: 'active',
    rating: 4.6,
    reviewCount: 420,
    createdAt: new Date().toISOString(),
    updatedAt: new Date().toISOString(),
  },
]

// 用户Mock数据
export const mockUser: User = {
  id: '1',
  username: 'testuser',
  nickname: '测试用户',
  avatar: 'https://via.placeholder.com/100x100?text=头像',
  phone: '13800138000',
  email: 'test@example.com',
  gender: 'unknown',
  level: 1,
  points: 100,
  balance: 0,
  status: 'active',
  createdAt: new Date().toISOString(),
  updatedAt: new Date().toISOString(),
}

// 地址Mock数据
export const mockAddresses: Address[] = [
  {
    id: '1',
    userId: '1',
    name: '张三',
    phone: '13800138000',
    province: '广东省',
    city: '深圳市',
    district: '南山区',
    detail: '科技园南区深圳湾科技生态园10栋A座',
    postalCode: '518000',
    isDefault: true,
    createdAt: new Date().toISOString(),
    updatedAt: new Date().toISOString(),
  },
  {
    id: '2',
    userId: '1',
    name: '李四',
    phone: '13900139000',
    province: '广东省',
    city: '广州市',
    district: '天河区',
    detail: '珠江新城CBD中心区',
    isDefault: false,
    createdAt: new Date().toISOString(),
    updatedAt: new Date().toISOString(),
  },
]

// 订单Mock数据
export const mockOrders: Order[] = [
  {
    id: '1',
    orderNo: '202412251234567890',
    userId: '1',
    status: 'pending_payment',
    items: [
      {
        id: '1',
        orderId: '1',
        productId: '1',
        product: mockProducts[0],
        quantity: 1,
        price: 999900,
        totalPrice: 999900,
      },
    ],
    totalQuantity: 1,
    totalPrice: 999900,
    discountAmount: 0,
    shippingFee: 0,
    finalPrice: 999900,
    shippingAddress: mockAddresses[0],
    createdAt: new Date(Date.now() - 2 * 60 * 60 * 1000).toISOString(),
    updatedAt: new Date().toISOString(),
  },
  {
    id: '2',
    orderNo: '202412251234567891',
    userId: '1',
    status: 'shipped',
    items: [
      {
        id: '2',
        orderId: '2',
        productId: '3',
        product: mockProducts[2],
        quantity: 2,
        price: 189900,
        totalPrice: 379800,
      },
    ],
    totalQuantity: 2,
    totalPrice: 379800,
    discountAmount: 0,
    shippingFee: 0,
    finalPrice: 379800,
    paymentMethod: 'wechat',
    paymentTime: new Date(Date.now() - 24 * 60 * 60 * 1000).toISOString(),
    shippingAddress: mockAddresses[0],
    shippingTime: new Date(Date.now() - 12 * 60 * 60 * 1000).toISOString(),
    createdAt: new Date(Date.now() - 25 * 60 * 60 * 1000).toISOString(),
    updatedAt: new Date().toISOString(),
  },
]

// 评价Mock数据
export const mockReviews: Review[] = [
  {
    id: '1',
    userId: '1',
    productId: '1',
    orderId: '1',
    rating: 5,
    content: '商品质量很好，物流也很快，包装完整，非常满意！',
    images: [],
    isAnonymous: false,
    createdAt: new Date(Date.now() - 7 * 24 * 60 * 60 * 1000).toISOString(),
    updatedAt: new Date().toISOString(),
    user: {
      id: '1',
      nickname: '测试用户',
      avatar: 'https://via.placeholder.com/100x100?text=头像',
    },
  },
  {
    id: '2',
    userId: '2',
    productId: '1',
    orderId: '2',
    rating: 4,
    content: '整体不错，性价比高，推荐购买',
    images: [],
    isAnonymous: true,
    createdAt: new Date(Date.now() - 5 * 24 * 60 * 60 * 1000).toISOString(),
    updatedAt: new Date().toISOString(),
    user: {
      id: '2',
      nickname: '匿名用户',
      avatar: 'https://via.placeholder.com/100x100?text=匿名',
    },
  },
]

// 优惠券Mock数据
export const mockCoupons: Coupon[] = [
  {
    id: '1',
    name: '新用户专享',
    type: 'fixed',
    value: 5000, // 50元
    minAmount: 10000, // 满100元
    validFrom: new Date().toISOString(),
    validTo: new Date(Date.now() + 30 * 24 * 60 * 60 * 1000).toISOString(),
    totalCount: 1000,
    usedCount: 120,
    userLimit: 1,
    status: 'active',
    description: '新用户专享50元优惠券，满100元可用',
    createdAt: new Date().toISOString(),
  },
  {
    id: '2',
    name: '全场通用',
    type: 'percent',
    value: 0.95, // 95折
    minAmount: 20000, // 满200元
    maxDiscount: 10000, // 最大优惠100元
    validFrom: new Date().toISOString(),
    validTo: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000).toISOString(),
    totalCount: 500,
    usedCount: 80,
    userLimit: 2,
    status: 'active',
    description: '全场通用95折券，满200元可用，最大优惠100元',
    createdAt: new Date().toISOString(),
  },
  {
    id: '3',
    name: '包邮券',
    type: 'shipping',
    value: 0,
    minAmount: 5000, // 满50元
    validFrom: new Date().toISOString(),
    validTo: new Date(Date.now() + 15 * 24 * 60 * 60 * 1000).toISOString(),
    totalCount: 2000,
    usedCount: 300,
    userLimit: 3,
    status: 'active',
    description: '包邮券，满50元免运费',
    createdAt: new Date().toISOString(),
  },
]

// 生成随机商品数据
export function generateRandomProduct(categoryId: string = '1'): Product {
  const names = [
    '智能手机', '笔记本电脑', '平板电脑', '智能手表', '无线耳机',
    '台式机', '显示器', '键盘', '鼠标', '音响'
  ]
  
  const descriptions = [
    '高性能处理器，优质体验',
    '轻薄便携，性能卓越',
    '大屏高清，色彩丰富',
    '智能监测，健康生活',
    '无线连接，音质出众'
  ]
  
  const images = [
    'https://via.placeholder.com/300x300?text=商品图片1',
    'https://via.placeholder.com/300x300?text=商品图片2',
    'https://via.placeholder.com/300x300?text=商品图片3',
  ]
  
  const randomIndex = Math.floor(Math.random() * names.length)
  const price = Math.floor(Math.random() * 100000) + 10000 // 100-1000元
  const originalPrice = price + Math.floor(Math.random() * 50000) // 原价更高
  
  return {
    id: generateId('product_'),
    name: names[randomIndex],
    description: descriptions[randomIndex],
    categoryId,
    images: [images[Math.floor(Math.random() * images.length)]],
    defaultPrice: price,
    originalPrice,
    sales: Math.floor(Math.random() * 1000),
    stock: Math.floor(Math.random() * 100) + 1,
    status: 'active',
    rating: Number((Math.random() * 2 + 3).toFixed(1)), // 3-5分
    reviewCount: Math.floor(Math.random() * 500),
    createdAt: new Date().toISOString(),
    updatedAt: new Date().toISOString(),
  }
}

// 生成随机订单数据
export function generateRandomOrder(userId: string): Order {
  const statuses: Order['status'][] = [
    'pending_payment', 'pending_shipment', 'shipped', 'delivered', 'completed'
  ]
  
  const status = statuses[Math.floor(Math.random() * statuses.length)]
  const product = generateRandomProduct()
  const quantity = Math.floor(Math.random() * 3) + 1
  
  return {
    id: generateId('order_'),
    orderNo: Date.now().toString() + Math.floor(Math.random() * 1000),
    userId,
    status,
    items: [
      {
        id: generateId('order_item_'),
        orderId: '',
        productId: product.id,
        product,
        quantity,
        price: product.defaultPrice,
        totalPrice: product.defaultPrice * quantity,
      },
    ],
    totalQuantity: quantity,
    totalPrice: product.defaultPrice * quantity,
    discountAmount: 0,
    shippingFee: 0,
    finalPrice: product.defaultPrice * quantity,
    shippingAddress: mockAddresses[0],
    createdAt: new Date(Date.now() - Math.random() * 30 * 24 * 60 * 60 * 1000).toISOString(),
    updatedAt: new Date().toISOString(),
  }
}